﻿using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
using System.Web.Mvc;
using static Learun.Application.TwoDevelopment.ZZDT_EC.ProjectSugar;
using static Learun.Util.SqlSugar.SqlSugarHelper;

namespace Learun.Application.Web.Areas.ZZDT_EC.Controllers
{
    /// <summary>
    /// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
    /// Copyright (c) 2013-2018 Hexagon PPM
    /// 创 建：超级管理员
    /// 日 期：2022-02-23 11:30
    /// 描 述：信号属性历史记录
    /// </summary>
    public class ec_wire_group_propertyhisController : MvcControllerBase
    {
        #region 视图功能

        /// <summary>
        /// 主页面
        /// <summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取页面显示列表数据
        /// <summary>
        /// <param name="queryJson">查询参数</param>
        /// <param name="engineDataID">工程数据ID</param>
        /// <returns></returns>
        [HttpGet]
        [AjaxOnly]
        public ActionResult GetPageList(string pagination, string queryJson)
        {
            Pagination paginationobj = pagination.ToObject<Pagination>();
            var queryParam = queryJson.ToJObject();
            var projectId = queryParam["ProjectId"].ToString();
            var WireGroupID = queryParam["WireGroupID"]?.ToString();
            var PropertyName = queryParam["PropertyName"]?.ToString();
            var tableName = TableName<ec_wire_group_propertyhisEntity>(projectId);

            int totalNumber = 0;
            int totalPage = 0;
            var data = Db.Queryable<ec_wire_group_propertyhisEntity>().AS(tableName)
                .WhereIF(!string.IsNullOrEmpty(WireGroupID), x => x.WireGroupID == WireGroupID)
                .WhereIF(!string.IsNullOrEmpty(PropertyName), x => x.PropertyName.Contains(PropertyName))
                .ToPageList(paginationobj.page, paginationobj.rows, ref totalNumber, ref totalPage);
            paginationobj.records = totalNumber;
            paginationobj.total = totalPage;
            var jsonData = new
            {
                rows = data,
                total = paginationobj.total,
                page = paginationobj.page,
                records = paginationobj.records
            };
            return Success(jsonData);
        }
        #endregion
    }
}
